/** @Fields: base url */
const basePath = '/active-item'

/** @Fields: 商品激活 */
const itemStatus = 5

/** @Fields: 商品转类型 */
const itemType = 7

/** ------------------商品状态 start --------------------------- */
/** @Fields: 商品状态-供应商已撤销 */
const ITEM_STATUS_REVOKE = 0

/** @Fields: 商品状态-已提交初审 */
const ITEM_STATUS_SUBMITTED = 1

/** @Fields: 商品状态-初审已驳回 */
const ITEM_STATUS_REJECTED = -2

/** @Fields: 商品状态-初审已通过 */
const ITEM_STATUS_AGREED = 2

/** 首次校验中 */
const ITEM_STATUS_FIRST_VALIDATION = 3

/** 商品状态-初次校验通过 */
const ITEM_STATUS_FIRST_VALIDATION_SUCCESS = 4

/** 商品状态-初次校验失败 */
const ITEM_STATUS_FIRST_VALIDATION_FAIL = -4

/** 商品状态-BPMS流程中 */
const ITEM_STATUS_BPMS = 5

/** 商品状态-二次校验/BPMS审批通过 */
const ITEM_STATUS_SECONDE_VALIDATION = 6

/** 商品状态-BPMS审批驳回 */
const ITEM_STATUS_BPMS_REJECTED = -6

/** 商品状态-二次校验成功 */
const ITEM_STATUS_SECONDE_VALIDATION_SUCCESS = 7

/** 商品状态-MDA审核通过 */
const ITEM_STATUS_MDA_AGREE = 10

/** 商品状态-MDA审核驳回 */
const ITEM_STATUS_MDA_REJECT = -10

/** 商品状态-item file审核通过 */
const ITEM_STATUS_ITEM_FILE_AGREE = 11

/** 商品状态-item file审核驳回 */
const ITEM_STATUS_ITEM_FILE_REJECT = -11

/** 商品状态-vendor 提交供应商处理中 */
const ITEM_STATUS_VENDOR_PROCESSING = 12

/** 商品状态-vendor 提交供应商处理失败 */
const ITEM_STATUS_VENDOR_PROCESS_FAIL = 13

/** 商品状态-采购新增 */
const ITEM_STATUS_BUYER_ADD = 14

/** 商品状态-结束 */
const ITEM_STATUS_OVER = 100

/** 商品状态-结束 */
const ITEM_STATUS_DELETE = -1
/** ------------------商品状态 end --------------------------- */

/** 商品状态-激活 */
const DETAIL_ACTIVE_PAGE = 1

/** 商品状态-转类型 */
const DETAIL_CHANGE_TYPE_PAGE = 2

/** 商品状态-初审 */
const DETAIL_AUDIT_PAGE = 3

/** 商品状态-校验 */
const DETAIL_VALIDATE_PAGE = 4

/** 商品状态-提交审核 */
const DETAIL_SUBMIT_AUDIT_PAGE = 5

/** ------------------商品状态步骤定义 start --------------------------- */
const StepDef = {
  buyerAdd: { // 采购新增
    name: '采购新增',
    icon: 'el-icon-user-solid',
    present: function(itemStatus) {
      return ITEM_STATUS_VENDOR_PROCESS_FAIL === itemStatus || ITEM_STATUS_BUYER_ADD === itemStatus
    }
  },
  vendorAdd: { // 供应商补充
    name: '供应商补充',
    icon: 'el-icon-user-solid',
    present: function(itemStatus) {
      return itemStatus === ITEM_STATUS_BPMS_REJECTED ||
        itemStatus === ITEM_STATUS_REVOKE ||
        itemStatus === ITEM_STATUS_VENDOR_PROCESSING
    }
  },
  vendorSubmit: { // 供应商提交
    name: '供应商提交',
    icon: 'el-icon-user-solid',
    present: function(itemStatus) {
      return itemStatus === ITEM_STATUS_SUBMITTED
    }
  },
  buyerAudit: { // 采购初审
    name: '初审',
    icon: 'el-icon-user-solid',
    present: function(itemStatus) {
      return itemStatus === ITEM_STATUS_SUBMITTED
    }
  },
  buyerEdit: { // 采购编辑
    name: '采购编辑',
    icon: 'el-icon-user',
    present: function(itemStatus) {
      return itemStatus === ITEM_STATUS_BPMS_REJECTED ||
        itemStatus === ITEM_STATUS_FIRST_VALIDATION_FAIL ||
        itemStatus === ITEM_STATUS_MDA_REJECT ||
        itemStatus === ITEM_STATUS_ITEM_FILE_REJECT
    }
  },
  systemValidate: { // 系统校验
    name: '系统校验',
    icon: 'el-icon-s-platform',
    present: function(itemStatus) {
      return itemStatus === ITEM_STATUS_FIRST_VALIDATION_SUCCESS ||
        itemStatus === ITEM_STATUS_FIRST_VALIDATION ||
        itemStatus === ITEM_STATUS_AGREED
    }
  },
  auditProcess: { // 审核流程
    name: '审核流程',
    icon: 'el-icon-upload',
    present: function(itemStatus) {
      return itemStatus === ITEM_STATUS_BPMS ||
        itemStatus === ITEM_STATUS_MDA_AGREE ||
        itemStatus === ITEM_STATUS_ITEM_FILE_AGREE
    }
  },
  finish: { // 结束
    name: '已发送Item File',
    icon: 'el-icon-s-platform',
    present: function(itemStatus) {
      return itemStatus === ITEM_STATUS_OVER
    }
  }
}

function getStep(itemStatus, stepDefs) {
  // console.log('stepDefs:' + JSON.stringify(stepDefs))
  // console.log('itemStatus:' + itemStatus)
  for (var i = 0; i < stepDefs.length; i++) {
    if (stepDefs[i].present(itemStatus)) {
      return i
    }
  }
}
/** ------------------商品状态步骤定义 end --------------------------- */

export default {
  basePath,
  itemStatus,
  itemType,
  StepDef,
  getStep,
  ITEM_STATUS_REVOKE,
  ITEM_STATUS_SUBMITTED,
  ITEM_STATUS_REJECTED,
  ITEM_STATUS_AGREED,
  ITEM_STATUS_FIRST_VALIDATION,
  ITEM_STATUS_FIRST_VALIDATION_SUCCESS,
  ITEM_STATUS_FIRST_VALIDATION_FAIL,
  ITEM_STATUS_BPMS,
  ITEM_STATUS_SECONDE_VALIDATION,
  ITEM_STATUS_BPMS_REJECTED,
  ITEM_STATUS_SECONDE_VALIDATION_SUCCESS,
  ITEM_STATUS_MDA_AGREE,
  ITEM_STATUS_MDA_REJECT,
  ITEM_STATUS_ITEM_FILE_AGREE,
  ITEM_STATUS_ITEM_FILE_REJECT,
  ITEM_STATUS_VENDOR_PROCESSING,
  ITEM_STATUS_VENDOR_PROCESS_FAIL,
  ITEM_STATUS_BUYER_ADD,
  ITEM_STATUS_OVER,
  ITEM_STATUS_DELETE,
  DETAIL_ACTIVE_PAGE,
  DETAIL_CHANGE_TYPE_PAGE,
  DETAIL_AUDIT_PAGE,
  DETAIL_VALIDATE_PAGE,
  DETAIL_SUBMIT_AUDIT_PAGE
}
